package models

import (
	"time"

	"gorm.io/gorm"
)

// MaEventType [...]
type MaEventType struct {
	ID              string    `gorm:"autoIncrement:true;primaryKey;column:id;type:int;not null"  json:"id" json_old:"ID"`
	Name            string    `gorm:"column:name;type:varchar(30);not null;comment:事件类型的含义"  json:"name" json_old:"Name"`
	AddTime         time.Time `gorm:"column:add_time;type:datetime;not null;comment:添加时间" json:"-" json_old:"-"`
	AddTimeFormated string    `gorm:"-" json:"add_time" json_old:"AddTime"`
	CreatedAt       int64     `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
}

// TableName get sql table name.获取数据库表名
func (m MaEventType) TableName() string {
	return "ma_event_type"
}

func (m *MaEventType) AfterFind(tx *gorm.DB) (err error) {
	if !m.AddTime.IsZero() {
		AddTimeByte, _ := DateTime(m.AddTime).MarshalDateTime()
		m.AddTimeFormated = string(AddTimeByte)
	}
	return
}

// 模式自动注册
func init() {
	Models = append(Models, &MaEventType{})
}
